﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Bezier_Curve
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }



        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Random random = new Random();
            
            int width = pictureBox1.Width;
            int height = pictureBox1.Height;
            Font f = Font;

            Graphics g = e.Graphics;

            int x1 = random.Next(0, width);
            int x2 = random.Next(0, width);
            int x3 = random.Next(0, width);
            int y1 = random.Next(0, height);
            int y2 = random.Next(0, height);
            int y3 = random.Next(0, height);



            bool firstIteration = true;
            float lastX = 0;
            float lastY = 0;
          //  for (x1 = 1; x1 < width; x1+=30)
            {
                for (float t = 0; t <= 1; t += (float)0.01)
                {
                    float newX;
                    float newY;
                    newX = F(t, x1, x2, x3);
                    newY = F(t, y1, y2, y3);

                    if (firstIteration)
                    {
                        lastX = newX;
                        lastY = newY;
                        firstIteration = false;
                        continue;
                    }

                    g.DrawLine(Pens.Magenta, lastX, lastY, newX, newY);

                    lastX = newX;
                    lastY = newY;
                }


                g.DrawLine(Pens.Magenta, x1, y1, x2, y2);
                g.DrawLine(Pens.Magenta, x2, y2, x3, y3);
            }

        }



        private float F(float t, int a, int b, int c)
        {
            return (1-t)*(1-t)*a+2*t*(1-t)*b+t*t*c;


        }

        #region bull shit
        private void Form1_Resize(object sender, EventArgs e)
        {
            pictureBox1.Width = Width;
            pictureBox1.Height = Height;

            pictureBox1.Invalidate();
        }
        #endregion
    }
}
